package com.ntschy.taizhou.dao;


import com.ntschy.taizhou.entity.StoreOrderCensusDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Mapper
public interface StoreOrderCensusDao {


  @Select("  select DISTINCT brand_name  from store_order_census ")
    List<String> getBrandName();
  @Select("  select DISTINCT business_segment  from store_order_census ")
  List<String> getBusinessSegment();
  @Select("  select DISTINCT sector  from store_order_census ")
  List<String> getSector();
  @Select("  select DISTINCT category  from store_order_census ")
  List<String> getCategory();
  @Select("  select DISTINCT sales_destination  from store_order_census ")
  List<String> getSalesDestination();
  @Select("  select sum(gmv) as gmv ,  sum(revenue) as revenue  from store_order_census where  time>=#{startTime} and #{endTime} >=time ")
  StoreOrderCensusDto getAllCensus(@Param("startTime") String startTime, @Param("endTime") String endTime);
  @Select("  select MAX(time)  from store_order_census ")
  String getMaxTime();
  @Select("  select MIN(time)  from store_order_census ")
  String getMinTime();
//  @Select("  select sum(gmv) as gmv  from store_order_census where  time=#{startDate} " +
//          "" )
  @Select({"<script>",
          " select sum(gmv) as gmv  from store_order_census where  time=#{startDate} ",
          "<when test='brandName!=null'>",
          "AND brand_name = #{brandName}",
          "</when>",
          "<when test='businessSegment!=null'>",
          "AND business_segment = #{businessSegment}",
          "</when>",
          "<when test='sector!=null'>",
          "AND sector = #{sector}",
          "</when>",
          "<when test='category!=null'>",
          "AND category = #{category}",
          "</when>",
          "<when test='salesDestination!=null'>",
          "AND sales_destination = #{salesDestination}",
          "</when>",
          "</script>"})

  BigDecimal getGmvArea(@Param("startDate")String startDate,@Param("brandName") String brandName, @Param("businessSegment")String businessSegment,
                        @Param("sector")String sector, @Param("category")String category,@Param("salesDestination") String salesDestination);

  @Select({"<script>",
          " select sum(revenue) as revenue  from store_order_census where  time=#{startDate} ",
          "<when test='brandName!=null'>",
          "AND brand_name = #{brandName}",
          "</when>",
          "<when test='businessSegment!=null'>",
          "AND business_segment = #{businessSegment}",
          "</when>",
          "<when test='sector!=null'>",
          "AND sector = #{sector}",
          "</when>",
          "<when test='category!=null'>",
          "AND category = #{category}",
          "</when>",
          "<when test='salesDestination!=null'>",
          "AND sales_destination = #{salesDestination}",
          "</when>",
          "</script>"})

  BigDecimal getRevenueArea(@Param("startDate")String startDate,@Param("brandName") String brandName, @Param("businessSegment")String businessSegment,
                        @Param("sector")String sector, @Param("category")String category,@Param("salesDestination") String salesDestination);
}
